package com.hmy.material.controller;

import com.hmy.material.domain.HmyMateriaFeedStore;
import com.hmy.material.domain.HmyMateriaFeedType;
import com.hmy.material.service.TypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zxh
 * @version 1.0
 * @description: 饲料类型控制器
 * @date 2024/2/28 17:19
 */
@RestController
@RequestMapping("type")
public class TypeController extends BaseController {

    @Autowired
    private TypeService typeService;

    @RequiresPermissions("material:type:list")
    @GetMapping("list")
    public TableDataInfo selectTypeList(String type, String dateStart, String dateEnd){
        startPage();
        List<HmyMateriaFeedType> typeList = typeService.selectTypeList(type, dateStart, dateEnd);
        return getDataTable(typeList);
    }

    /**
     * 根据ID获取单个饲料信息
     * @param id
     * @return
     */
    @RequiresPermissions("material:type:query")
    @GetMapping("getInfo/{id}")
    public AjaxResult selectTypeById(@PathVariable Long id){
        return AjaxResult.success(typeService.selectTypeById(id));
    }

    @RequiresPermissions("material:type:add")
    @PostMapping("add")
    public AjaxResult addType(@RequestBody HmyMateriaFeedType type) {
        return toAjax(typeService.addType(type));
    }

    @RequiresPermissions("material:type:update")
    @PostMapping("update")
    public AjaxResult updateType(@RequestBody HmyMateriaFeedType store){
        return toAjax(typeService.updateType(store));
    }

    /**
     * 根据ID删除饲料信息
     * @param delIds
     * @return
     */
    @DeleteMapping("del/{delIds}")
    @RequiresPermissions("material:type:del")
    public AjaxResult delTypeById(@PathVariable  Long[] delIds){
        return toAjax(typeService.delTypeByIds(delIds));
    }

    /**
     * 获取饲料类型  在其他模块作为下拉框出现
     * @return
     */
    @GetMapping("getTypes")
    public AjaxResult getTypes(){
        return AjaxResult.success(typeService.getTypes());
    }
}
